package Text2;

import java.util.Arrays;
import java.util.Comparator;

/*
 *@Student 张策
 */
public class Main {
    public static void main(String[] args) {
        Book[] books= new Book[4];
        books[0]=new Book("西游记a",100);
        books[1]=new Book("斗破s",200);
        books[2]=new Book("大力",300);
        books[3]=new Book("邙",400);
       Arrays.sort(books, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                Book book1=(Book)o1;
                Book book2=(Book)o2;
//                return book2.getPrice()-book1.getPrice();
                return book1.getName().length()-book2.getName().length();
            }
        });
        for (int i = 0; i < books.length; i++) {
            System.out.println(books[i].toString());
        }
    }
//    public static void sort(Book[] book, Comparator c){
//        for (int i = 0; i < book.length; i++) {
//            Book tem;
//            for (int j = 0; j < book.length-1-i; j++) {
//                if(c.compare(book[j].getPrice(),book[j+1].getPrice())>0){
//                    tem=book[j];
//                    book[j]=book[j+1];
//                    book[j+1]=tem;
//                }
//            }
//        }
//    }
}
//public class Main {
//    public static void main(String[] args) {
//      Book[] books= new Book[4];
//      books[0]=new Book("西游记",100);
//      books[1]=new Book("斗破",200);
//      books[2]=new Book("大力",300);
//      books[3]=new Book("邙山",400);
//      sort(books, new Comper() {
//          @Override
//          public int eat(int a,int b) {
//              return b-a;
//          }
//      });
//        for (int i = 0; i < books.length; i++) {
//            System.out.println(books[i].toString());
//        }
//    }
//    public static void sort(Book[] book,Comper c){
//        for (int i = 0; i < book.length; i++) {
//            Book tem;
//            for (int j = 0; j < book.length-1-i; j++) {
//                if(c.eat(book[j].getPrice(),book[j+1].getPrice())>0){
//                    tem=book[j];
//                    book[j]=book[j+1];
//                    book[j+1]=tem;
//                }
//            }
//        }
//    }
//}
